package com.cynoware.busappmas.contentprovider;


import java.io.File;

import com.cynoware.busappmas.model.PeakVolumeInfo;
import com.cynoware.busappmas.model.StationDirectory;
import com.cynoware.busappmas.model.StationPicInfo;
import com.cynoware.busappmas.model.VideoInfo;
import com.cynoware.busappmas.util.GZipUtils;
import com.cynoware.busappmas.util.GeneralUtil;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

public class DbPeakVolume {

	private static final String TAG = "DbPeakVolume";

	private ContentResolver mContentResolver;

	private DbHelper dh;
	
	public DbPeakVolume(ContentResolver mContentResolver,Context content){
		this.mContentResolver = mContentResolver;
		this.dh = new DbHelper(content);
	}
	
	
	public PeakVolumeInfo[] getPeakVolumeInfo(){
		
		String[] projection ={DbHelper.COLUME_PEAKVOLUME_ORDER,DbHelper.COLUME_PEAKVOLUME_BEGINTIME,
					DbHelper.COLUME_PEAKVOLUME_ENDTIME,DbHelper.COLUME_PEAKVOLUME_VOLUME};
		Cursor cursor = mContentResolver.query(DbContentProvider.CONTENT_URI_PEAKVOLUME, projection,null,null, null);
		int i=0;
		if(cursor.getCount()!=0){
			PeakVolumeInfo[] info=new PeakVolumeInfo[cursor.getCount()];
			while(cursor.moveToNext()){
				info[i]= new PeakVolumeInfo();
				info[i].setOrder(cursor.getInt(0));
				info[i].setBeginTime(cursor.getString(1));
				info[i].setEndTime(cursor.getString(2));
				info[i].setVolume(cursor.getInt(3));			
				i++;			
			}
			cursor.close();
			return info;
		}
		else {
			cursor.close();
			return null;
		}
		
	}
	
	public void deletePeakTimeVolume(int order){
		mContentResolver.delete(DbContentProvider.CONTENT_URI_PEAKVOLUME, DbHelper.COLUME_PEAKVOLUME_ORDER+"=?" , new String[]{String.valueOf(order)});
	}
	
	public void InsertPeakTimeVolume(PeakVolumeInfo info){
		ContentValues cv = new ContentValues();
		cv.put(DbHelper.COLUME_PEAKVOLUME_ORDER, info.getOrder());
		cv.put(DbHelper.COLUME_PEAKVOLUME_BEGINTIME, info.getBeginTime());
		cv.put(DbHelper.COLUME_PEAKVOLUME_ENDTIME, info.getEndTime());
		cv.put(DbHelper.COLUME_PEAKVOLUME_VOLUME, info.getVolume());
		mContentResolver.insert(DbContentProvider.CONTENT_URI_PEAKVOLUME,  cv);

	}
	
		
}
